package com.yaoxun.bored.common;

import org.apache.commons.lang3.StringUtils;

public class QueryParams {
	
	public static final int LIMIT = 10;
	
	public static final int MAX_LIMIT = 100; //每页最大数量
	
	public static final int PAGE = 1;
	
	private String page;
	
	private String limit;
	
	private String orderBy;

	private String startTime;
	
	private String endTime;
	
	
	public String getOrderBy() {
		return orderBy;
	}
	
	public void setOrderBy(String orderBy) {
		this.orderBy = orderBy;
	}

	public String getPage() {
		return page;
	}

	public void setPage(String page) {
		this.page = page;
	}

	public String getLimit() {
		return limit;
	}

	public void setLimit(String limit) {
		this.limit = limit;
	}

	public String getStartTime() {
		return startTime;
	}

	public void setStartTime(String startTime) {
		this.startTime = startTime;
	}

	public String getEndTime() {
		return endTime;
	}

	public void setEndTime(String endTime) {
		this.endTime = endTime;
	}
	
	public int getLimitInt() {
		if(StringUtils.isNotBlank(this.limit)) {
			try {
				int res = Integer.valueOf(this.limit);
				if(res > MAX_LIMIT) {
					res = MAX_LIMIT;
				}
				return res;
			}catch(Exception e) {
				return LIMIT;
			}
		}
		return LIMIT;
	}
	
	public int getPageInt() {
		if(StringUtils.isNotBlank(this.page)) {
			try {
				return Integer.valueOf(this.page);				
			}catch(Exception e) {
				return PAGE;
			}
		}
		return PAGE;
	}

	@Override
	public String toString() {
		return "QueryParams [page=" + page + ", limit=" + limit + ", orderBy=" + orderBy + ", startTime=" + startTime
				+ ", endTime=" + endTime + "]";
	}
	
}
